<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">
<!--	拼票预测-->
	<script type="text/html" id="toolbar_in_form">
	</script>

	<div id="id_panel">
	</div>
	<script th:inline="javascript">
	
	var dto = [[${dto}]]
	dto.footer.show = 0;
	dto.saveBtn.state = 0;
	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/'
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
		form = layui.form,
		laydate = layui.laydate,
		YsForm = layui.YsForm,
		YsModal = layui.YsModal
		/* 
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
		{
			id:'id_panel', // 页面容器ID
			dto: $.parseJSON(JSON.stringify(dto)),
			callback: function() {
				
			}
		}
		);

		$('#' + formObj.c.id_header).find('.bg_color_white').find('.layui-inline').append('<button type="button" class="layui-btn layui-btn-normal" id="logisticsDetails" lay-submit onclick="toAdd()">确认</button>');
		$('#' + formObj.c.id_header).find('.bg_color_white').find('.layui-inline').append('<button type="button" class="layui-btn layui-btn-primary" id="costsDetails"  onclick="toClose()">取消</button>');


		//重写弹出框
		formObj.showModal=function(modalKey, colCode) {
			var t = formObj;
			if(colCode == 'logsticsChannelName'){//物流方式弹框
				var cck = formObj.getValueByName("cck");//仓库
				var country = formObj.getValueByName("country");//国家
				var transportationId = formObj.getValueByName("transportationId");//运输类型
				var nameLogsticsClearance = formObj.getValueByName("nameLogsticsClearance");//清关方式
				layui.YsModal.init({modalKey: modalKey, colCode: colCode, parentObj: t, extraData:{}, conditionsDefault: [], sameCode: 'xx'
					// ,pathGridRequest: '/api/inter/tccLogisticsChannelMaint/searchPlan?cck='+cck
					,pathGridRequest: '/api/inter/tccLogisticsChannelMaint/searchPlan?'
				});
							// + '&country=' + country
							// +'&transportationId=' + transportationId
							// +'&nameLogsticsClearanceTrue=' + "6"});

			} else{
				// 打开单选框,
				layui.YsModal.init({modalKey: modalKey, colCode: colCode, parentObj: t, extraData:{}, conditionsDefault: [{code: 'aaa', value:'123'},{code: 'bbb', value:'456'}], sameCode: 'xx'});
			}
		}

		formObj.matchValuesAfterModalSelectRadio = function(colCode, rowSelected, extraData) {
			var t = formObj;
			var domForm = $('#' + t.c.id_form);
			if (colCode == 'logsticsChannelName'){
				showloadings(true);
				//查询后台数据
				var list = formObj.getValueByName("list");
				var fbaWarehouseAddr = formObj.getValueByName("fbaWarehouseAddr");//目的地
				$.ajax({
					url: '/api/inter/tccLogisticsPlan/ppMarkTicket',
					data: "list=" + list
							+'&fbaWarehouseAddr=' + fbaWarehouseAddr
							+ "&id=" +rowSelected.id,
					type: 'POST',
					async: true,
					success: function (res) {
						if (res.code == 0) {
							let data = res.data;
							formObj.setValueByName("czCnPp",data.czCnPp);
							formObj.setValueByName("numProName",data.numProName);
							formObj.setValueByName("priceProNameExtraPredictTol",data.priceProNameExtraPredictTol);
							formObj.setValueByName("priceQualityExtraPredictTol",data.priceQualityExtraPredictTol);
							formObj.setValueByName("priceTranPredictTol",data.priceTranPredictTol);
							formObj.setValueByName("proNameNum",data.proNameNum);
							formObj.setValueByName("restrictionShipment",data.restrictionShipment);
							formObj.setValueByName("ticketWeight",data.ticketWeight);
							formObj.setValueByName("weightCalPp",data.weightCalPp);
							formObj.setValueByName("weightRealPp",data.weightRealPp);
							formObj.setValueByName("weightVolPp",data.weightVolPp);
							formObj.setValueByName("logsticsChannelName",rowSelected.logsticsChannelName);
							formObj.setValueByName("logsticsChannelId",rowSelected.id);

							//单票起重（kg）
							formObj.setValueByName("singlePassCrane",data.singlePassCrane);
							//单票品名上限
							formObj.setValueByName("maxProNameNum",data.maxProNameNum);
							//盈亏率
							formObj.setValueByName("profitLoss",data.profitLoss);
							//发货盈亏
							formObj.setValueByName("profitLossShipment",data.profitLossShipment);
							//拼票费用（总）
							formObj.setValueByName("ticketFee",data.ticketFee);
							//计重费用（拼）
							formObj.setValueByName("priceTranCalWeight",data.priceTranCalWeight);
							//计重梯度价（￥/kg）
							formObj.setValueByName("jfFee",data.jfFee);
							//目的地附加计费（￥/kg）
							formObj.setValueByName("additionalBilling",data.additionalBilling);
							//品名附加费（拼）
							formObj.setValueByName("priceProNameExtraPredictPp",data.priceProNameExtraPredictPp);
							//材质附加费（拼）
							formObj.setValueByName("priceQualityExtraPredict",data.priceQualityExtraPredict);

							formObj.c.subGridObj.clearRows();
							formObj.c.subGridObj.addRows(data.tccFbaFeeDetailsList);

							showloadings(false);

						} else {
							layer.msg(res.msg);
						}
					}, error: function () {
						layer.close();
						layer.msg("拼票发货标记失败，请稍后再试！", {icon: 2});
					}
				});
			}
		};
	});
	//取消
	function toClose() {
		window.parent.layer.closeAll();
	}
	//确认
	function toAdd() {
		let restrictionShipment = formObj.getValueByName("restrictionShipment");
		if (restrictionShipment == null){
			return layer.msg("物流渠道名称不允许为空!");
		}
		if (restrictionShipment == '限制发货'){
			return layer.msg("本次拼票不满足物流渠道要求!");
		}

		let profitLossShipment = formObj.getValueByName("profitLossShipment");
		let profitLoss = formObj.getValueByName("profitLoss");
		let list = formObj.getValueByName("list");
		let logsticsChannelId = formObj.getValueByName("logsticsChannelId");
		let tableId = formObj.getValueByName("tableId");
		let rowClickId = formObj.getValueByName("rowClickId");
		let remark = "本次拼票" +profitLossShipment+"，盈亏率（"+profitLoss+"），请确认是否拼票?";
		layer.confirm(remark, {icon: 3}, function () {
			showloadings(true);
			$.ajax({
				url: '/api/inter/tccLogisticsPlan/ppMarkNew',
				data: {"list": list,
					"logsticsChannelId":logsticsChannelId
				},
				type: 'POST',
				async: true,
				success: function (res) {
					if (res.code == 0) {
						layer.msg(res.msg);
						setTimeout(function(){
							showloadings(false);
							// parent.parent.window[1].gridObj.c.isLoadRowClick = 123; // 是否已经加载单击子列表
							parent.window.layer.closeAll();
							parent.window.layui.table.reload(rowClickId, {data: null});
							parent.window.layui.table.reload(tableId);
							$('div[lay-id="' + rowClickId + '"]').remove();
						}, 1000);
					} else {
						showloadings(false);
						parent.window.layui.table.reload(rowClickId, {data: null});
						parent.window.layui.table.reload(tableId);
						$('div[lay-id="' + rowClickId + '"]').remove();
						layer.alert(res.msg);
					}
				}, error: function () {
					layer.close();
					layer.msg("拼票发货标记失败，请稍后再试！", {icon: 2});
				}
			});
		}, function () {
		});
	}

	//加载中
	 function showloadings(t) {
		if (t) {//如果是true则显示loading
			layer.load(2, {
				shade: [0.1, '#000'] //0.1透明度的白色背景
			});
		} else {//如果是false则关闭loading
			layer.closeAll();
		}
	}
	</script>
</body>
</html>
